Reviewing the Stylebits Parameters
The four parameters of stylebits are AddBit, RemoveBit, AddExtendedBit, RemoveExtendedBit. For a review of these four parameters, and an introduction to Stylebits in general, please read [Stylebits Corner - An Introduction]. For examples of stylebits changing the appearance and input of textboxes, see [Stylebits Corner - Textboxes]. To see Statictext changes with stylebits, see [Stylebits Corner - Statictext].
Stylebits and Button Labels

Many of the stylebits statictext border effects can be obtained with buttons as well. Use the same windows style _WS_ prefixes seen in changing window and other control edges. You can even add a titlebar to a button. These stylebits give a bit of variety to the button appearance and may enhance the overall 3D effect.
_WS_BORDER, 0, 0, 0 _WS_DLGFRAME _WS_CAPTION, _WS_MAXIMIZEBOX 0, 0, _WS_EX_CLIENTEDGE, 0 0, 0, _WS_EX_CLIENTEDGE or _WS_EX_DLGMODALFRAME, 0
Stylebits and Tabbing
Pressing the TAB key can cycle focus from one control to the next. The cycling order is the same order as that which the controls are created. Sometimes it may be desirable to not include a control in the tabbed cycle. The programmer may not want the QUIT button to be included in the TAB Cycle so that the user doesn't inadvertently exit a program prematurely. Assigning the stylebit _WS_TABSTOP to the RemoveBit (second) stylebits parameter will keep that button from gaining focus in the TAB sequence. The button does remain active and will receive focus when mouseclicked.
Stylebits and Formatted Text Labels
The stylebits commands to format button text labels are similar to those _ES_ textbox and statictext formatting commands. Button formatting style commands begin with _BS_. The default style is text that remains on one line centered both vertically and horizontally. With stylebits, you can left justify, right justify, center, place text at the top of the button and place text at the bottom of the button. The most useful of these stylebits is the _BS_MULTILINE which allows word wrapping and multiline button labels.
_BS_LEFT _BS_CENTER 'The Default _BS_RIGHT _BS_TOP _BS_BOTTOM _BS_MULTLINE
Stylebits and API Calls
Stylebits allow buttons to display images, but only when accompanied by an API call to user32.dll (SendMessageA). For an indepth explanation of placing images on button controls, see [API Corner - Easy BmpButtons] by [Alyce Watson]. In this article, Alyce also explains how using Stylebits with BmpButtons preserves the intended recessed look of the button when clicked, rather than the inverse color effect on the non-Stylebits native Liberty Basic BmpButton. If you use the _BS_BITMAP stylebit, be sure to include the height and width of the bitmap as the height and width of the button. Otherwise, the button size defaults to that of the null character of the chosen font. As with statictext, you can combine _BS_BITMAP with border styles to achieve interesting effects. Try making colorful buttons in your program without having to preload bitmap images.
' Demonstrates colorful buttons without first
' having to load bitmaps
Nomainwin
Open "Quick Draw" for Graphics as #1
#1, "Trapclose [close1]"
#1, "Down"
hBmp1 = solidButton()
hBmp2 = varigatedButton()
hBmp3 = stripedButton()
Close #1
Button #demo.b1, "", [click], UL, 20, 20, 50, 50
Stylebits #demo.b1, _BS_BITMAP, 0, _WS_EX_CLIENTEDGE OR _WS_EX_DLGMODALFRAME, 0
Button #demo.b2, "", [click], UL, 20, 100, 50, 50
Stylebits #demo.b2, _BS_BITMAP OR _WS_DLGFRAME, 0, 0, 0
Button #demo.b3, "", [click], UL, 20, 180, 50, 50
Stylebits #demo.b3, _BS_BITMAP OR _WS_BORDER, 0, 0, 0
Open "Colorful Buttons" for Window as #demo
#demo "Trapclose [endDemo]"
hButton1 = hWnd(#demo.b1)
Call CreateBMPButton hButton1, hBmp1
hButton2 = hWnd(#demo.b2)
Call CreateBMPButton hButton2, hBmp2
hButton3 = hWnd(#demo.b3)
Call CreateBMPButton hButton3, hBmp3
[click]
Wait
[endDemo]
Close #demo
End
Sub CreateBMPButton hButton, hBmp
CallDLL #user32, "SendMessageA",_
hButton As Long, _ 'handle of button
_BM_SETIMAGE As Long,_ 'message to set new image
_IMAGE_BITMAP as long,_ 'type of image
hBmp As Long,_ 'handle of bitmap
re As Long
End Sub
Function solidButton()
hue$ = "128 0 128"
#1, "Backcolor ";hue$
#1, "Color ";hue$
#1, "Place 0 0"
#1, "Boxfilled 50 50"
#1, "Getbmp button1 1 1 50 50"
solidButton = hBmp("button1")
End Function
Function varigatedButton()
c1 = 51: c2 = 101
blueHue = 232
For i = 1 to 25
#1, "Color 0 0 ";blueHue
#1, "Place ";c1;" ";c1
#1, "Box ";c2;" ";c2
c1 = c1+1: c2 = c2-1
blueHue = blueHue-8
Next i
#1, "Flush"
#1, "Getbmp button2 51 51 50 50"
varigatedButton = hBmp("button2")
End Function
Function stripedButton()
hueStrand$ = "Red White Blue White Red"
For i = 0 to 4
hue$ = Word$(hueStrand$, i+1)
#1, "Color ";hue$
For j = 1 to 10
#1, "Line ";50+i*10+j;" 0 ";50+i*10+j;" 50"
Next j
Next i
#1, "Flush"
#1, "Getbmp button3 50 0 50 50"
stripedButton = hBmp("button3")
End Function
The Stylebits Corner Series
What else can be done with stylebits? In the coming months the STYLEBITS command will be used to, among other things,
Eager to try Stylebits with buttons and other window controls? Can't wait for the next newsletter? Good news! The best way to explore and assign stylebit commands is with the Stylebits Wizard option found in Alyce Watson's [Liberty BASIC Workshop].
DEMO
The file stylebitsDemo5.bas is included in the zipped archive of this newsletter.
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::